using System;
using System.Collections.Generic;
using System.Text;

using DTO;
using System.Collections;
using System.Data;
namespace DAOLayer
{
    public class ThuThuDAO:AbStractDao
    {
        public ThuThuDAO()
        {
            this.connect();
        }
        
        public static DataTable getListThuThu()
        {
            string query = "SELECT * FROM ThuThu";
            ThuThuDAO dgDao = new ThuThuDAO();
            DataTable dt = dgDao.fillDataTable(query);
            dgDao.disconnect();           
            return dt;
        }
        public static ThuThuDTO getThuThu(string maThuThu)
        {
            string strQuery = "select * from ThuThu where TenNguoiDung= '" + maThuThu  + "'";
            ThuThuDAO dgDao = new ThuThuDAO();
            IDataReader dr = dgDao.executeQuery(strQuery);
            ThuThuDTO dgDto = new ThuThuDTO();
            if (dr.Read())
            {
                dgDto.TenNguoiDung = dr.GetString(0);
                dgDto.MatKhau = dr.GetString(1);
                dgDto.HoTen = dr.GetString(2);
                dgDto.NgaySinh = dr.GetDateTime(3);
                
            }
            dgDao.disconnect();
            return dgDto;
        }
        public bool insert(ref ThuThuDTO info)
        {

            string insertCommand = "INSERT INTO ThuThu(TenNguoiDung,passWord,HoTen,NgaySinh) VALUES('" +
                info.TenNguoiDung + "', '" +
                info.MatKhau + "', '" +
                info.HoTen + "', '" +
                info.NgaySinh + "')";
            bool flag = executeNonQuery(insertCommand);     
            return flag;
        }
        public bool update(ThuThuDTO info)
        {
            string updateCommand = "UPDATE ThuThu " +
                                    "SET hoTen = '" + info.HoTen + "', NgaySinh='" + info.NgaySinh + ", passWord='" + info.MatKhau +
                                    "' WHERE tenNguoiDung = " + info.TenNguoiDung;
            bool flag = this.executeNonQuery(updateCommand);
    
            return flag;
        }
        public bool delete(int maThuThu)
        {
            string deleteCommand = "DELETE FROM ThuThu WHERE MaThuThu = " + maThuThu;
            bool flag = this.executeNonQuery(deleteCommand);
            return flag;
        }
    }
}
